package nl.infodation.emr.pricingservice.ui.component;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;

@SuppressWarnings("rawtypes")
public class ExplicitPagingContainer extends AbstractRowContainer  {
	private static final long serialVersionUID = 1L;

	private int pageSize = 10;

	private List<BeanItem> currentPage = new ArrayList<BeanItem>();
	
	public ExplicitPagingContainer () {
		setNumberOfRows(0);
	}
	
	public int getItemCount() {
		return currentPage.size();
	}
	
	public Item getItem(Object  itemId) {
		if (!currentPage.isEmpty()){
			return currentPage.get((Integer) itemId);
		}
		return null;
	}
	
	public void setDataSource(List<BeanItem> beans){
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// No-op
		}
		currentPage.clear();
		currentPage.addAll(beans);
		setNumberOfRows(beans.size());
	}

	public Object firstItemId() {
		return 0;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(final int newPageSize) {
		pageSize = newPageSize;
	}
	
}
